package com.firefly.admin.login.controller;

import com.firefly.admin.common.annotations.annotation.LoginLog;
import com.firefly.admin.login.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.firefly.admin.common.constant.Constants;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.login.vo.LoginInfoVo;
import com.firefly.admin.login.vo.RouterInfoVo;
import com.firefly.admin.login.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "系统登录相关信息API")
@RequestMapping("/system")
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 系统管理员登录接口
     *
     * @param loginInfoVo 登录信息
     * @return 登录结果
     */
    @ApiOperation(value = "系统管理员登录接口", notes = "系统管理员通过用户名和密码登录系统", httpMethod = "POST")
    @LoginLog(operateType = Constants.LoginOperateType.LOGIN)
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginInfoVo loginInfoVo) {
        return loginService.login(loginInfoVo);
    }

    /**
     * 获取用户信息结果
     *
     * @return 用户信息
     */
    @ApiOperation(value = "获取登录用户信息接口", notes = "获取登录用户信息接口", httpMethod = "GET")
    @GetMapping("/login/user")
    public Result<UserInfoVo> getLoginUser() {
        return loginService.getLoginUser();
    }

    /**
     * 获取登录用户路由列表接口
     *
     * @return 路由信息
     */
    @ApiOperation(value = "获取登录用户路由列表接口", notes = "获取登录用户路由列表接口", httpMethod = "GET")
    @GetMapping("/user/router/list")
    public Result<List<RouterInfoVo>> getMenuList() {
        return loginService.getMenuList();
    }

    /**
     * 系统管理员登出接口
     *
     * @return 操作结果
     */
    @ApiOperation(value = "系统管理员登出接口", notes = "系统管理员登出接口", httpMethod = "POST")
    @PostMapping("/logout")
    public Result<String> logout() {
        return loginService.logout();
    }

    /**
     * 系统管理员登出接口
     *
     * @return 操作结果
     */
    @ApiOperation(value = "系统管理员登出接口", notes = "系统管理员登出接口", httpMethod = "POST")
    @LoginLog(operateType = Constants.LoginOperateType.LOGOUT)
    @PostMapping("/hand/logout")
    public Result<String> handLogout() {
        return loginService.logout();
    }

    /**
     * 获取验证码信息接口
     *
     * @return 验证码信息
     */
    @ApiOperation(value = "获取验证码信息接口", notes = "获取验证码信息接口", httpMethod = "GET")
    @GetMapping("/verify/code")
    public Result<Map<String, String>> getVerifyCode() {
        return loginService.getVerifyCode();
    }
}
